package top.zk123.chain.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import top.zk123.chain.bean.ReturnInfo;
import top.zk123.chain.exception.FileEmptyException;
import top.zk123.chain.exception.FileUploadException;
import top.zk123.chain.exception.WrongFileTypeException;
import top.zk123.chain.service.VerifyService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 证书核验 接口层
 *
 * @author Ke Zhang
 * @since 2.0
 */
@RestController
public class VerifyController {

    @Resource
    VerifyService verifyService;

    /**
     * 读取 json 文件
     *
     * @param files 文件
     * @return ReturnInfo
     */
    @PostMapping(value = "/verify")
    public ReturnInfo verify(@RequestParam(value = "files") MultipartFile[] files) throws FileEmptyException, WrongFileTypeException, FileUploadException {
        return verifyService.verifyCerts(files);
    }

    /**
     * 查看证书详细信息
     *
     * @param UId 证书 UId
     * @return ReturnInfo
     */
    @GetMapping(value = "/verify/detail")
    public ReturnInfo getCertDetail(@RequestParam(value = "UId") String UId) {
        return verifyService.getCertDetail(UId);
    }

    @GetMapping(value = "/verify/exportExcel/selected")
    public ReturnInfo exportExcelSelected(HttpServletRequest request, HttpServletResponse response,
                                          @RequestParam(value = "UIdList") List<String> UIdList) {
        return verifyService.exportExcelSelected(request, response, UIdList);
    }

    @GetMapping(value = "/verify/exportExcel/all")
    public ReturnInfo exportExcelAll(HttpServletRequest request, HttpServletResponse response) {
        return verifyService.exportExcelAll(request, response);
    }

}
